#ifndef QWRISTWATCHWIDGET_H
#define QWRISTWATCHWIDGET_H

#include <QWidget>
#include <QTimer>
#include <QPropertyAnimation>

class QWristWatchWidget : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(qreal angle WRITE setAngle READ angle)

public:
    explicit QWristWatchWidget(QWidget *parent = nullptr);
    ~QWristWatchWidget();

    qreal angle() const;
    void setAngle(const qreal &angle);

    typedef enum {
        Clock,
        LCDClock,
        StopWatch,
        Compass,
    } WatchType;

    void setWatchType(int type);

signals:

private slots:
    void sltTimeout();

private:
    QString getDirection(qreal _angle = 0);

    void clearStopwatch();
    bool isClearStopwatch();

private:
    qreal m_angle;
    QPropertyAnimation *m_animation;
    QTimer *m_timer;
    QString m_strText;

    bool m_isPressed;
    bool m_isMoved;
    QPoint m_startPos;

    WatchType m_clockType;
    qreal m_scale;
    QRect m_updateRect;
    QRect m_recordRect;
    QRect m_startRect;

    qint8 m_hour;
    qint8 m_minute;
    qint8 m_second;
    qint8 m_msecond;

    QStringList m_stopWatchRcd;
protected:
    void paintEvent(QPaintEvent *) override;
    // clock
    void drawClockScale(QPainter *painter);
    void drawClockHandle(QPainter *painter);

    // stopwatch
    void drawStopwatchScale(QPainter *painter);
    void drawStopwatchHandle(QPainter *painter);

    // compass
    void drawCompassClockDial(QPainter *painter);
    void drawCompassHandle(QPainter *painter);

    void mousePressEvent(QMouseEvent *e) override;
    void mouseMoveEvent(QMouseEvent *e) override;
    void mouseReleaseEvent(QMouseEvent *e) override;
    void mouseDoubleClickEvent(QMouseEvent *e) override;

    QSize sizeHint() const override;
    void hideEvent(QHideEvent *event) override;
    void showEvent(QShowEvent *event) override;
    void resizeEvent(QResizeEvent *event) override;
};

#endif // QWRISTWATCHWIDGET_H
